/*
 * @Author: ipk518 18163976442@163.com
 * @Date: 2023-08-19 16:03:22
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2023-11-24 16:10:54
 * @FilePath: /WingsUpdater-main/src/PackageResolver/IPackageResolver.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

#include <mutex>
#include "IPackageResolver.h"
#include "PackageResolverTcp.h"
#include "PackageResolverUdp.h"

std::shared_ptr<IPackageResolver> IPackageResolver::instance(const int which) 
{
    static std::shared_ptr<IPackageResolver> multiton[PACKAGE_RESOLVER_NUM];
    static std::once_flag onlyOnce;
    std::call_once(onlyOnce, [&]{
        multiton[PACKAGE_RESOLVER_INDEX_UDP] = std::shared_ptr<IPackageResolver>(new PackageResolverUdp);
        multiton[PACKAGE_RESOLVER_INDEX_TCP] = std::shared_ptr<IPackageResolver>(new PackageResolverTcp);
    });

    return multiton[which];
}

Result IPackageResolver::respond(const bool success, const std::string &detail) 
{
    return Result(ErrorKind::ExecuteFailed);
}

const std::string &IPackageResolver::type()const 
{
    return m_type;
}
